package cn.wolfcode.luowowo.mgrsite.web.controller;

import cn.wolfcode.luowowo.article.domain.Travel;
import cn.wolfcode.luowowo.article.domain.TravelContent;
import cn.wolfcode.luowowo.article.query.TravelQueryObject;
import cn.wolfcode.luowowo.article.service.ITravelService;
import cn.wolfcode.luowowo.common.domain.AjaxResult;
import cn.wolfcode.luowowo.common.query.QueryObject;
import cn.wolfcode.luowowo.mgrsite.uitl.UploadUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/travel")
public class TravelController {

    @Reference
    private ITravelService travelService;

    /**
     * 游记管理页面
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String travelList(@ModelAttribute("qo") TravelQueryObject qo, Model model){

        PageInfo pageInfo = travelService.queryForList(qo);
        model.addAttribute("pageInfo",pageInfo);

        return "travel/list";
    }

    /**
     * 游记发布和下架
     * @param id
     * @param state
     * @return
     */
    @RequestMapping("/changeReleaseState")
    @ResponseBody
    public AjaxResult changeReleaseState(Long id, Long state){
        AjaxResult ajaxResult = new AjaxResult();

        travelService.changeReleaseState(id,state);

        return ajaxResult;
    }

       /**
     * 获取文章内容
     * @param id
     * @return
     */
    @RequestMapping("/content")
    @ResponseBody
    public AjaxResult content(Long id){
        AjaxResult ajaxResult = new AjaxResult();

        TravelContent content = travelService.getContentById(id);
        ajaxResult.setResult(content.getContent());

        return ajaxResult;
    }





}
